package gamagora.game.world.backgrounds
{
	import gamagora.game.entity.OSEntity;
	import gamagora.game.world.maps.OSMap;
	
	public class OSBackgroundManager extends OSEntity
	{
		private static const BACKGROUND1_DECAL:Number = -0.2;
		private static const BACKGROUND2_DECAL:Number = -0.1;
		private static const BACKGROUND3_DECAL:Number = 0;
		
		private var _layer1:OSBackgroundLayer;
		private var _layer2:OSBackgroundLayer;
		private var _layer3:OSBackgroundLayer;
		
		public function OSBackgroundManager(nbMaps:uint)
		{
			super(NOTHING);
			_hide = true;
			
			var scrollLeftBound:Number = OSMap.WIDTH / 2;
			var scrollRightBound:Number = nbMaps * OSMap.WIDTH - scrollLeftBound;
			_layer1 = new OSBackgroundLayer(BACKGROUND1_DECAL, scrollLeftBound, scrollRightBound);
			_layer2 = new OSBackgroundLayer(BACKGROUND2_DECAL, scrollLeftBound, scrollRightBound);
			_layer3 = new OSBackgroundLayer(BACKGROUND3_DECAL, scrollLeftBound, scrollRightBound);
			
			OSBackgroundFactory.GetLayer1(_layer1);
			OSBackgroundFactory.GetLayer2(_layer2);
			OSBackgroundFactory.GetLayer3(_layer3);
			
			_layer1.generateRandomBackgrounds(6);
			_layer2.generateRandomBackgrounds(6);
			_layer3.generateRandomBackgrounds(6);
			
			//On cache certains backgrounds pour le taj et la fin
			_layer1.hideBackgrounds([33, 34, 35, 45, 46, 47]);
			_layer2.hideBackgrounds([37, 38, 39, 51, 52, 53]);
			_layer3.hideBackgrounds([42, 43, 57, 58, 59]);
			
			add(_layer1);
			add(_layer2);
			add(_layer3);
		}
		
		public function stopScroll():void
		{
			_layer1.stopScroll();
			_layer2.stopScroll();
			_layer3.stopScroll();
		}

		public function get layer1():OSBackgroundLayer
		{
			return _layer1;
		}

		public function get layer2():OSBackgroundLayer
		{
			return _layer2;
		}

		public function get layer3():OSBackgroundLayer
		{
			return _layer3;
		}
	}
}
